package com.qian.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qian.mapper.EmployeeMapper;
import com.qian.pojo.Employees;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService extends ServiceImpl<EmployeeMapper, Employees> {
    @Resource
    private EmployeeMapper employeeMapper;

    //根据姓名查询，模糊查询
    public List<Employees> searchUserByName(String employeeName) {
        QueryWrapper<Employees> wrapper = new QueryWrapper<>();
        wrapper.like("employee_name", employeeName);
        List<Employees> list = employeeMapper.selectList(wrapper);
        return list;
    }

    //根据用户id查询
    public Employees searchUserById(Long employeeId) {
        return employeeMapper.selectById(employeeId);
    }

    //增加用户
    public void addUser(Employees employees) {
        employeeMapper.insert(employees);
    }

    //更新用户
    public void updateUser(Employees employees) {
        employeeMapper.updateById(employees);
    }

    //删除用户
    public void deleteUser(Long employeeId) {
        employeeMapper.deleteById(employeeId);
    }

    //修改密码
    public void updatePsd(Long employeeId, String employeePassword) {
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.set("employee_password", employeePassword);
        Employees employees = employeeMapper.queryTenantById(employeeId);
        employeeMapper.update(employees, wrapper);
    }
}
